namespace Admin2025.Domain.Entities.App;

public class AppUser : EntityBase
{
  // public Guid UserId { get; set; }

  public string UserName { get; set; } = null!;
  public string Password { get; set; } = null!;

  // 方便对密码进行加密，防止被人破解
  public string Salt { get; set; } = null!;

  public string Email { get; set; } = string.Empty;
  public string PasswordHash { get; set; } = string.Empty;
  public Guid? DepartmentId { get; set; }  // 部门ID
  public AppDepartment? Department { get; set; }    // 部门信息

  public List<AppRole> Roles { get; set; } = new();

  // 分配角色
  public void AssignRole(AppRole role)
  {
    if (!Roles.Contains(role))
    {
      Roles.Add(role);
    }
  }
  // 移除角色
  public void RemoveRole(AppRole role)
  {
    if (Roles.Contains(role))
    {
      Roles.Remove(role);
    }
  }

  // 修改密码
  public void ChangePassword(string newPassword, string salt)
  {
    Password = newPassword;
    Salt = salt;
  }
}